package org.autumn.juc;

import lombok.extern.slf4j.Slf4j;

import java.util.Hashtable;

/**
 * this class is  unsafe
 */
@Slf4j
public class MultiMethodProblem {
    public static void main(String[] args) throws InterruptedException {
        Hashtable<String, String> table = new Hashtable<>();

        Thread t1 = new Thread(() -> {
            if (table.get("k1") == null) {
                log.info("get k1 = null");
                table.put("k1", "v1");
            }
        }, "t1");

        Thread t2 = new Thread(() -> {
            if (table.get("k1") == null) {
                log.info("get k1 = null");
                table.put("k1", "v2");
            }
        }, "t2");

        t1.start();
        t2.start();
        t1.join();
        t2.join();

        log.info(table.get("k1"));

    }
}
